import 'package:flutter/material.dart';
import 'package:torch_controller/torch_controller.dart';

/// 厦门大学计算机专业 | 前华为工程师
/// 专注《零基础学编程系列》https://cxyxy.blog.csdn.net/article/details/121134634
/// 包含：Java | 安卓 | 前端 | Flutter | iOS | 小程序 | 鸿蒙
/// 公众号：花生皮编程

void main() {
  TorchController().initialize();
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      debugShowCheckedModeBanner: false,
      home: HspPage(title: '手电筒-花生皮编程'),
    );
  }
}

class HspPage extends StatefulWidget {
  const HspPage({Key? key, required this.title}) : super(key: key);

  final String title;

  @override
  State<HspPage> createState() => _HspPageState();
}

class _HspPageState extends State<HspPage> {
  final controller = TorchController();
  double? intensity;
  Color buttonColor = Colors.white70;

  @override
  Widget build(BuildContext context) {
    var platform = Theme.of(context).platform;
    if (platform == TargetPlatform.iOS) {
      intensity = 1;
    }
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            IconButton(
              iconSize: 60,
              icon: const Icon(
                Icons.power_settings_new_rounded,
                color: Colors.red,
              ),
              onPressed: () {
                if (platform == TargetPlatform.iOS) {
                  controller.toggle(intensity: intensity);
                } else {
                  controller.toggle();
                }
              },
            ),
          ],
        ),
      ),
    );
  }
}
